//
// Copyright (C) Robert Bosch GmbH
// Date: March 2010
// Author: CR/RTC2-AP Kui Xu

//#include "stdafx.h"
#include "UIOSAL.h"

using namespace std;

////////////////////////For memory/////////////////////////
void* UIMemory::ReserveMemory(size_t stAllocSize)
{
#ifdef OSAL

#else
	return operator new(stAllocSize);
#endif
}

void UIMemory::ReleaseMemory(void *pMemory)
{
#ifdef OSAL

#else
	operator delete(pMemory);
#endif
}

void UIMemory::ReleaseMemoryArray(void *pMemory)
{
#ifdef OSAL

#else
	operator delete[](pMemory);
#endif
}

////////////////////////For file/////////////////////////
void UIFile::openFile(const char* filename)
{
#ifdef OSAL

#else
	ifs.open(filename);
#endif
}

void UIFile::openOutFile(const char* filename)
{
#ifdef OSAL

#else
	ofs.open(filename);
#endif
}

void UIFile::openFileBin(const char* filename)
{
#ifdef OSAL

#else
	ifs.open(filename, std::ios::binary);
#endif
}

void UIFile::movePointerTo(int i)
{
#ifdef OSAL

#else
	ifs.seekg(i);
#endif
}

void UIFile::readBuff(char * dest, int n)
{
#ifdef OSAL

#else
	ifs.read(dest, n);
#endif
}

void UIFile::getChar(char &dest)
{
#ifdef OSAL

#else
	ifs.get(dest);
#endif
}

int UIFile::fileLen()
{
#ifdef OSAL

#else
	int len;
	ifs.seekg(0, std::ios::end);
	len = ifs.tellg();
	ifs.seekg(0);
	return len;
#endif
}

void UIFile::closeFile()
{
#ifdef OSAL

#else
	ifs.close();	

#endif
}

void UIFile::closeOutFile()
{
#ifdef OSAL

#else
	ofs.close();	

#endif
}

bool UIFile::isOpen()
{
#ifdef OSAL

#else
	return ifs.is_open();
#endif
}

bool UIFile::isEOF()
{
#ifdef OSAL

#else
	return ifs.eof();
#endif
}

bool UIFile::getLine(string &line)
{
#ifdef OSAL

#else
	if(getline(ifs, line))
		return true;
	else
		line="";
		return false;
#endif
}

void UIFile::writeLine(const char *dest)
{
#ifdef OSAL

#else
	ofs<<dest<<"\n";
	ofs.flush();
#endif
}

void UIFile::mkdir(const char* dirname)
{
#ifdef OSAL
#else
	//_mkdir(dirname);
#endif
}

